import 'package:flutter_easyloading/flutter_easyloading.dart';

///加载器工具类
class LoadingUtils {
  LoadingUtils._();
  static final LoadingUtils _singleton = LoadingUtils._();

  ///单例工厂方法
  factory LoadingUtils() => _singleton;

  ///显示进度条
  void showLoading({
    final String? message,
    final EasyLoadingMaskType? maskType,
  }) {
    if (maskType == EasyLoadingMaskType.clear) {
      EasyLoading.instance.maskType = EasyLoadingMaskType.clear;
    }
    EasyLoading.show(
      status: message ?? '加载中...',
      maskType: maskType ?? EasyLoadingMaskType.none,
    );
  }

  ///移除进度条
  void dismiss() {
    EasyLoading.dismiss();
  }

  ///显示toast
  showToast(final String msg, {Duration? duration}) {
    EasyLoading.showToast(msg, duration: duration);
  }
}

///加载工具单例
final loading = LoadingUtils();
